package controll;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.UUID;

import dao.UserDao;
import entity.User;

@WebServlet("/upload")
public class Register extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String bh= UUID.randomUUID().toString();
        String img=req.getParameter("imgbase64");
        User u=new User();
        u.setBh(bh);
        u.setImg(img);
        UserDao ud=new UserDao();
        System.out.println(ud);
        ud.save(u);
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out=resp.getWriter();
        out.write("注册成功");
        out.close();

    }
}
